- content_for :javascript do
  initialize_homepage();

- content_for :coverfade_class do
  = "without-text"

- content_for :extra_javascript do
  - # maps.google can't be loaded twice
  - maps_key = MarketplaceHelper.google_maps_key(@current_community.id)
  - key_param = maps_key ? "&key=#{maps_key}" : ""
  - # Topbar adds its own maps script, otherwise add it if location search enabled or map is visible
  - needs_maps = !FeatureFlagHelper.feature_enabled?(:topbar_v1) && (main_search != :keyword || @view_type.eql?("map"))
  - if(needs_maps)
    = javascript_include_tag "//maps.googleapis.com/maps/api/js?libraries=places#{key_param}"
  - if(@view_type.eql?("map"))
    = javascript_include_tag "markerclusterer.js"

- content_for :title_header do
  - is_homepage = params[:controller] == "homepage" && params[:action] == "index"
  - if @big_cover_photo
    - if @current_community.show_slogan?
      %h1.marketplace-lander-content-title= community_slogan.html_safe
    - else
      %h1.marketplace-lander-content-title.hidden_title_part &nbsp;
    - if @current_community.show_description?
      %p.marketplace-lander-content-description= community_description.html_safe
    - else
      %p.marketplace-lander-content-description.hidden-title-part &nbsp;
    - unless (is_homepage && !@current_community.private? && FeatureFlagHelper.feature_enabled?(:topbar_v1))
      .search-form
        - if @current_community.private?
          %a.inline-big-button{href: sign_up_path}
            .content
              = t("layouts.application.connect")
        - else
          - if(main_search == :location)
            = render partial: "location_bar"
          - else
            = render partial: "search_bar"
  - elsif !(is_homepage && FeatureFlagHelper.feature_enabled?(:topbar_v1))
    .browse-view-search-form
      - if(main_search == :location)
        = render partial: "location_bar"
      - else
        = render partial: "search_bar"

- content_for(:head) do
  - if seo_pagination_links[:prev].present?
    %link{rel: "prev", href: seo_pagination_links[:prev]}
  - if seo_pagination_links[:next].present?
    %link{rel: "next", href: seo_pagination_links[:next]}

- if @current_community.private? && @big_cover_photo
  - if @community_customization && @community_customization.private_community_homepage_content
    .community-customization-wrapper
      = @community_customization.private_community_homepage_content.html_safe
  - else
    = t(".this_is_private_community")

- else

  .home-toolbar

    - if listing_shape_menu_enabled || @category_menu_enabled
      .home-toolbar-show-filters-button-container
        .home-toolbar-show-filters-button#home-toolbar-show-filters
          = t(".filter")

    .home-toolbar-button-group{:class => listing_shape_menu_enabled || @category_menu_enabled ? "filters-enabled" : ""}
      - allowed_view_types.each do |view_type|
        - selected_class = @view_type == view_type ? "selected" : ""
        = link_to search_path(search_params.merge(view: view_type)), :class => "home-toolbar-button-group-button #{selected_class}", :title => t("homepage.filters.#{view_type}_button") do
          = icon_tag(view_type, ["icon-fix", "home-button-group-icon"])
          %span.home-toolbar-button-text
            = t("homepage.filters.#{view_type}_button")

    - if listing_shape_menu_enabled || @category_menu_enabled
      .home-toolbar-filters.home-toolbar-filters-mobile-hidden#home-toolbar-filters
        - if listing_shape_menu_enabled
          .toggle-container.home-toolbar-toggle-container
            .toggle.with-borders#home_toolbar-select-share-type{data: {toggle: '.home-toolbar-share-type-menu'}}
              .toggle-header-container
                .toggle-header
                  - if selected_shape
                    = t(selected_shape[:name_tr_key])
                  - else
                    = t("homepage.filters.all_listing_types")

                = icon_tag("dropdown", ["icon-dropdown"])

            .home-toolbar-share-type-menu.toggle-menu.hidden
              = link_to t("homepage.filters.all_listing_types"), search_path(search_params.merge({transaction_type: "all"}))
              - shapes.each do |shape|
                = link_to search_path(search_params.merge({transaction_type: shape[:name]})), class:  "toggle-menu-subitem" do
                  = t(shape[:name_tr_key])

        - if @show_categories
          .toggle-container.home-toolbar-toggle-container.hidden-tablet
            .toggle.with-borders{data: {toggle: '#home-toolbar-categories-menu'}}
              .toggle-header-container
                .toggle-header
                  - if selected_category
                    = @category_display_names[selected_category.id]
                  - else
                    = t("homepage.filters.all_categories")

                = icon_tag("dropdown", ["icon-dropdown"])
            #home-toolbar-categories-menu.toggle-menu
              = link_to t("homepage.filters.all_categories"), search_path(search_params.merge({category: "all"}))
              - @main_categories.each do |category|
                = link_to @category_display_names[category.id], search_path(search_params.merge({category: category}))
                - if category.children
                  - category.children.each do |child|
                    - is_selected = selected_category == child
                    = link_to @category_display_names[child.id], search_path(search_params.merge({category: child})), :class => "toggle-menu-subitem"

        / Filters
        .hidden-tablet
          - # Filters will be relocated to #desktop-filters when in desktop
          #filters
            = render :partial => "filters", :locals => { show_price_filter: show_price_filter, show_custom_fields: @show_custom_fields, filters: filters }

  .row
    - if @category_menu_enabled
      .col-3.visible-tablet
        - if @show_categories
          .row
            .col-12
              = link_to t("homepage.filters.all_categories"), search_path(search_params.merge({category: "all"})), :class => "home-categories-main #{if selected_category.nil? then 'selected' end}"
              - @main_categories.each do |category|
                - show_subcategories = show_subcategory_list(category, Maybe(selected_category).id.to_i.or_else(nil))
                = link_to @category_display_names[category.id], search_path(search_params.merge({category: category})), :class => "home-categories-main #{if show_subcategories then 'selected' end} #{if category.has_subcategories? then 'has-subcategories' end}", :data => {category: category.id}
                - if category.children
                  - if show_subcategories
                    - category.children.each do |child|
                      - is_selected = selected_category == child
                      = link_to @category_display_names[child.id], search_path(search_params.merge({category: child})), :class => "home-categories-sub #{if is_selected then 'selected' end}", :data => {:"sub-category" =>child.id}

        #desktop-filters
          - # Filters will be relocated here when in desktop

    - main_container_class = if @category_menu_enabled then "col-9" else "col-12" end
    %div{:class => main_container_class}
      - if @listings.total_entries > 0
        - if @view_type.eql?("map")
          .home-map
            = render :partial => "map", locals: { viewport: viewport }
        - else
          - if @view_type.eql?("grid")
            %div{class: @category_menu_enabled ? "home-fluid-thumbnail-grid-narrow" : "home-fluid-thumbnail-grid-wide"}
              .home-fluid-thumbnail-grid
                = render partial: "grid_item", collection: @listings, as: :listing, locals: { show_distance: location_search_in_use }
          - else
            .home-listings
              - if (location_search_in_use)
                = render partial: "list_item_with_distance", collection: @listings, as: :listing, locals: { shape_name_map: shape_name_map, show_distance: location_search_in_use }
              - else
                = render partial: "list_item", collection: @listings, as: :listing, locals: { shape_name_map: shape_name_map }
          .home-loading-more
            = will_paginate(@listings)
            - item_container = if @view_type.eql?("grid") then '.home-fluid-thumbnail-grid' else '.home-listings' end
            = pageless(@listings.total_pages, item_container, current_search_path_without_page, t('.loading_more_content'), current_page)
      - else
        .home-no-listings
          - if params[:q] || params[:category] || params[:share_type] # Some filter in use
            = t(".no_listings_with_your_search_criteria")
          - else
            = t(".no_listings_notification",
                  add_listing_link: link_to(t(".add_listing_link_text"),
                  new_listing_path(ref: "add_listing_link"))).html_safe
